﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Environment;
using Pixysoft.Weblications.Sango.Formular;
using Pixysoft.Weblications.Sango.Protocol.party;
using Pixysoft.Weblications.Sango.Protocol;

namespace Pixysoft.Weblications.Sango.Command.party
{
    partial class SangoPartyHandler
    {
        public party_memberinfo party_memberinfo(string userCode)
        {
            party_memberinfo response = ReflectionManager.CreatePojo<party_memberinfo>();
            response.Succeed = false;

            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);
            Entities.Usr_Partymember member = PartyDao.tryGetActiveMember(userCode);
            Entities.Usr_Party party = PartyDao.tryGetActiveParty(member.Partyprimarycode);

            int requireRanking = -1;

            if (member.Titletypecode >= PtyTitleSerialcodeCollection.POSITION_VICE_PRESIDENT)
            {
                requireRanking = -1;
            }
            else
            {
                Entities.Pty_Partytitle position = PtyPartyTitleHelper.searchByCode(member.Titletypecode + 1);
                int totalmembers = PartyDao.getTotalActiveMembers(party.Primarycode);
                requireRanking = (int)PartyFormular.getUpgradeRequiredRanking(position, totalmembers);
                int ranking = PartyDao.getMemberRanking(member.Partyprimarycode, member.Partycontributionvalue);
                response.rank = ranking;
            }

            response.member = PartyFacade.ToPartyMember(profile, party, member);
            response.upgraderank = requireRanking;
            response.Succeed = true;
            return response;
        }
    }
    public interface party_memberinfo : ISangoResponse
    {
        party_member member { get;set;}
        long rank { get;set;}
        long upgraderank { get;set;}
    }
}
